package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import dao.utils.GenericHibernateDAO;
import domain.LineaCompra;

public class LineaCompraDAOImpl extends GenericHibernateDAO implements
		LineaCompraDAO {

	public LineaCompraDAOImpl(Session s) {
		super(s);
	}

	public List<LineaCompra> findById(int id) {
		Query q = getSession().createQuery(
				"from LineaCompra as linea where linea.compra.idCompra = ?")
				.setInteger(0, id);

		if (q != null)
		{
		return q.list();
		}
		else
		{	
			return null;
		}
	}

	public boolean saveLC(LineaCompra lc) {
		try {
			getSession().save(lc);
			return true;
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return false;
		}
	}

	public boolean delete(LineaCompra lc) {
		try {
			getSession().delete(lc);

			return true;
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return false;
		}
	}

}